package cn.lanqiao.book.filter;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CharsetFilter  extends HttpFilter {
    private String charSet = "";
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        charSet =  filterConfig.getInitParameter("charset");
    }

    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(charSet);
        chain.doFilter(request,response);
    }
}